#include <iostream>
#include <string>
using namespace std;

//迭代子模式：迭代子模式可以顺序访问一个聚集中的元素而不必暴露聚集的内部表象。
//多个对象聚在一起形成的总体称之为聚集，聚集对象是能够包容一组对象的容器对象。

template <typename T>
class Iterator
{
public:
	virtual T next() = 0;
};

//迭代器
class StrIterator :public Iterator<char>
{
private:
	char *ch;
	int i = 0;
	int len = 0;
public:
	StrIterator(char *ch, int len)
	{
		this->ch = ch;
		this->len = len;
	}
	char next()override
	{
		return ch[i++];

	}

	bool hasNext()
	{
		return i < len-1 ? true : false; //最后一个结束符不算
	}
};
class MyStr
{
private:
	StrIterator* iterator;
public:
	MyStr(char ch[],int len)
	{
		iterator = new StrIterator(ch,len);
	}
	StrIterator* getIterator()
	{
		return iterator;
	}

};

void main7()
{
	char ch[] = "23423423wsrfqwer";
	MyStr * myStr = new MyStr(ch,sizeof(ch));
	StrIterator* it = myStr->getIterator();
	while (it->hasNext())
	{
		cout << it->next() << endl;
	}
	delete(myStr);
	system("pause");
}